package com.mezz.bones.im.logic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mezz.bones.im.logic.domain.entity.ChatConversation;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * IM会话列表 Mapper 接口
 * </p>
 *
 * @author mezz
 * @since 2024-12-20
 */
public interface IChatConversationMapper extends BaseMapper<ChatConversation> {

    @Update("UPDATE chat_conversation SET unread_count = unread_count + #{changeNum} WHERE id = #{conversationId}")
    void updateConversationUnreadNum(@Param("conversationId") String conversationId, @Param("changeNum") Integer changeNum);

    @Update("UPDATE chat_conversation SET unread_count = 0 WHERE id = #{conversationId}")
    void clearConversationUnreadNum(@Param("conversationId") String conversationId);

    @Select("SELECT COALESCE(SUM(unread_count), 0) FROM chat_conversation WHERE user_id = #{userId} AND is_del = 0")
    Long selectUnreadMessageCount(@Param("userId") String userId);
}
